package demo;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
//生成密钥对且写入文件中去
public class AESKey {
/*
    public static void main(String[] args) {

    KeyGenerator keyGen;

    {
        try {
            //生成密钥对
            keyGen = KeyGenerator.getInstance("AES");
            SecureRandom random = new SecureRandom();
            keyGen.init(128, random);
            SecretKey aesKey = keyGen.generateKey();
            byte[] aesKeyBytes = aesKey.getEncoded();
            //将密钥写入文件中
            String keyFile = "./key/key.dat";
            File keyFileObj = new File(keyFile);
            FileOutputStream keyOut = new FileOutputStream(keyFileObj);
            keyOut.write(aesKeyBytes);
            keyOut.close();

        } catch (NoSuchAlgorithmException | IOException e) {
            throw new RuntimeException(e);
        }
    }

    }*/


}
